*This file creates event study by skill intensity figure D.5

use  "$path/industry_data.dta", clear

*Define controls
global sharecontrols c.lnlabor_all1943#year  c.power_labor_share1943#year c.ln_relative_wage1943#year c.ln_establishments1943#year c.skilled1943#year c.ln_inputs_all1943#year c.ln_valueadded1943#year 


*Import industry skill. Based on values from Ciccone and Papaioannou (2009)
preserve
use "$path/ind_edu.dta" , clear
tempfile education
save `education' 
restore

joinby digt2 using `education' , unmatched (master) 

preserve
keep if year==1943
replace high_edu=0 if high_edu==.&repa_sharel==0
gen low_edu=(high_edu!=1)
replace low_edu=. if high_edu==.
gen h_std=repa_sharel*high_edu
egen h_std2=std(repa_sharel*high_edu)
gen l_std=repa_sharel*low_edu
egen l_std2=std(l_std)
keep isic h_std2 l_std2 low_edu high_edu
tempfile education2
save `education2' 
restore

drop _merge
joinby isic using `education2' , unmatched (master) 

*Labor force

forvalues x=34(1)70{
	gen repam19`x'=ydum19`x'*h_std2
	}
forvalues x=34(1)70{
	gen repal19`x'=ydum19`x'*l_std2
	}
	
local joku "1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970"

foreach l of local joku {
label var repam`l'  `l'
}

local repaflexible1 " repam1934 repam1935 repam1936 repam1937 repam1938 repam1939 repam1940 repam1941 repam1942 repam1944 repam1945 repam1946 repam1947 repam1948 repam1949 repam1950 repam1951 repam1952 repam1953 repam1954 repam1955 repam1956 repam1957 repam1958 repam1959 repam1960 repam1961 repam1962 repam1963 repam1964 repam1965 repam1966 repam1967 repam1968 repam1969 repam1970  "
local repaflexible2 " repal1934 repal1935 repal1936 repal1937 repal1938 repal1939 repal1940 repal1941 repal1942 repal1944 repal1945 repal1946 repal1947 repal1948 repal1949 repal1950 repal1951 repal1952 repal1953 repal1954 repal1955 repal1956 repal1957 repal1958 repal1959 repal1960 repal1961 repal1962 repal1963 repal1964 repal1965 repal1966 repal1967 repal1968 repal1969 repal1970  "
tempfile p31 p32

parmby  "reghdfe lnlabor_all  `repaflexible1' `repaflexible2'    , absorb(year isic $sharecontrols) vce(cluster isic)", lab saving(`"`p31'"',replace) idn(1) ids(Unadjusted) 


preserve
clear all
set obs 1
gen year =1943
gen estimate = 0
gen parm ="repam1943"
gen min95 =0
gen max95 =0
gen parmseq =0
append using `p31'
keep if regexm(parm, "^repam*")
gen yearstr =substr(parm, -4,4)
destring yearstr, replace
sort yearstr
keep if parmseq<37
tempfile tlabor3
save `tlabor3'
*title(Panel B: ln Labor Force)
restore 

preserve

clear all
set obs 1
gen year =1943
gen estimate = 0
gen parm ="repal1943"
gen min95 =0
gen max95 =0
gen parmseq =0
append using `p31'
keep if regexm(parm, "^repal*")
gen yearstr =substr(parm, -4,4)
destring yearstr, replace
sort yearstr
keep if parmseq>36
gen yearstr_l=yearstr-0.4
rename estimate estimate_l
rename min95 min95_l
rename max95 max95_l
append using `tlabor3'

twoway (scatter estimate yearstr , msize(medium) mcolor(dknavy))  (rspike   min95 max95 yearstr , lcolor(dknavy)) (scatter estimate_l yearstr_l ,msymbol(Oh) msize(medium) mcolor(dkgreen))  (rspike   min95_l max95_l yearstr_l , lcolor(dkgreen)),  xsize(6) ysize(4) xtitle(Year, ) xline(1944, lcolor(maroon)) xline(1952, lcolor(maroon)) title("Panel B: Estimates of ln Labor Force")  ///
 xlabel(1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970, ) plotregion(lcolor(white)) graphregion(lcolor(white) fcolor(white) color(white)) legend(order(1 "High-Skill exposure" 3 "Low-Skill exposure") position(6))  xlabel(#8)  xlabel(,grid nogextend ) ylabel(,grid nogextend)  ytitle("", margin(0 1 0 0))    saving(flexible_HS_labor.gph, replace)
restore


*Production

parmby  "reghdfe ln_value_prod  `repaflexible1' `repaflexible2'    , absorb(year isic $sharecontrols) vce(cluster isic)", lab saving(`"`p32'"',replace) idn(1) ids(Unadjusted) 

preserve
clear all
set obs 1
gen year =1943
gen estimate = 0
gen parm ="repam1943"
gen min95 =0
gen max95 =0
gen parmseq =0
append using `p32'
keep if regexm(parm, "^repam*")
gen yearstr =substr(parm, -4,4)
destring yearstr, replace
sort yearstr
keep if parmseq<37
tempfile tprod3
save `tprod3'
*title(Panel B: ln Labor Force)
restore 

preserve

clear all
set obs 1
gen year =1943
gen estimate = 0
gen parm ="repal1943"
gen min95 =0
gen max95 =0
gen parmseq =0
append using `p32'
keep if regexm(parm, "^repal*")
gen yearstr =substr(parm, -4,4)
destring yearstr, replace
sort yearstr
keep if parmseq>36
gen yearstr_l=yearstr-0.4
rename estimate estimate_l
rename min95 min95_l
rename max95 max95_l
append using `tprod3'

twoway (scatter estimate yearstr , msize(medium) mcolor(dknavy))  (rspike   min95 max95 yearstr , lcolor(dknavy)) (scatter estimate_l yearstr_l ,msymbol(Oh) msize(medium) mcolor(dkgreen))  (rspike   min95_l max95_l yearstr_l , lcolor(dkgreen)),  xsize(6) ysize(4) xtitle(Year, ) xline(1944, lcolor(maroon)) xline(1952, lcolor(maroon)) title("Panel A: Estimates of ln Value of Production")  ///
 xlabel(1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970, ) plotregion(lcolor(white)) graphregion(lcolor(white) fcolor(white) color(white)) legend(order(1 "High-Skill exposure" 3 "Low-Skill exposure") position(6))  xlabel(#8)  xlabel(,grid nogextend ) ylabel(,grid nogextend)  ytitle("", margin(0 1 0 0))    saving(flexible_HS_prod.gph, replace)
restore

*******
*Triple Difference
*******

use  "$path/ind_ddd.dta", clear

global sharecontrols2 c.ln_value_prod1943#year c.lnlabor_all1943#year 

drop if year==1970

forvalues x=34/69 {
gen ydum19`x'=0
replace ydum19`x'=1 if year==19`x'
}

forvalues x=34(1)69{
	gen repam19`x'=ydum19`x'*h_std2
	}

	forvalues x=34(1)69{
	gen repal19`x'=ydum19`x'*finland*h_std2
	}
	
forvalues x=34(1)69{
	gen repan19`x'=ydum19`x'*l_std2
	}

	forvalues x=34(1)69{
	gen repao19`x'=ydum19`x'*finland*l_std2
	}
	
local joku "1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969"

foreach l of local joku {
label var repam`l'  `l'
}

local repaflexible1 " repam1934 repam1935 repam1936 repam1937 repam1938 repam1939 repam1940 repam1941 repam1942  repam1944 repam1945 repam1946 repam1947 repam1948 repam1949 repam1950 repam1951 repam1952 repam1953 repam1954 repam1955 repam1956 repam1957 repam1958 repam1959 repam1960 repam1961 repam1962 repam1963 repam1964 repam1965 repam1966 repam1967 repam1968 repam1969  "

local repaflexible2 " repal1934 repal1935 repal1936 repal1937 repal1938 repal1939 repal1940 repal1941 repal1942  repal1944 repal1945 repal1946 repal1947 repal1948 repal1949 repal1950 repal1951 repal1952 repal1953 repal1954 repal1955 repal1956 repal1957 repal1958 repal1959 repal1960 repal1961 repal1962 repal1963 repal1964 repal1965 repal1966 repal1967 repal1968 repal1969  "

local repaflexible3 " repan1934 repan1935 repan1936 repan1937 repan1938 repan1939 repan1940 repan1941 repan1942  repan1944 repan1945 repan1946 repan1947 repan1948 repan1949 repan1950 repan1951 repan1952 repan1953 repan1954 repan1955 repan1956 repan1957 repan1958 repan1959 repan1960 repan1961 repan1962 repan1963 repan1964 repan1965 repan1966 repan1967 repan1968 repan1969  "

local repaflexible4 " repao1934 repao1935 repao1936 repao1937 repao1938 repao1939 repao1940 repao1941 repao1942  repao1944 repao1945 repao1946 repao1947 repao1948 repao1949 repao1950 repao1951 repao1952 repao1953 repao1954 repao1955 repao1956 repao1957 repao1958 repao1959 repao1960 repao1961 repao1962 repao1963 repao1964 repao1965 repao1966 repao1967 repao1968 repao1969  "

tempfile t1 t2 t3 t4

parmby  "reghdfe ln_value_prod    `repaflexible2'  `repaflexible4' `repaflexible1' `repaflexible3', absorb(year_country isic_country   $sharecontrols2) vce(cluster isic_country)", lab saving(`"`t1'"',replace) idn(1) ids(Unadjusted)


parmby  "reghdfe lnlabor_all  `repaflexible2'  `repaflexible4' `repaflexible1' `repaflexible3', absorb(year_country isic_country   $sharecontrols2) vce(cluster isic_country)", lab saving(`"`t2'"',replace) idn(1) ids(Unadjusted)

*Production

preserve
clear all
set obs 1
gen year =1943
gen estimate = 0
gen parm ="repal1943"
gen min95 =0
gen max95 =0
gen parmseq =0
append using `t1'
keep if regexm(parm, "^repal*")
gen yearstr =substr(parm, -4,4)
destring yearstr, replace
sort yearstr
keep if parmseq<36
tempfile tprod3
save `tprod3'
*title(Panel B: ln Labor Force)
restore 

preserve
clear all
set obs 1
gen year =1943
gen estimate = 0
gen parm ="repao1943"
gen min95 =0
gen max95 =0
gen parmseq =0
append using `t1'
keep if regexm(parm, "^repao*")
gen yearstr =substr(parm, -4,4)
destring yearstr, replace
sort yearstr
keep if parmseq>35&parmseq<71
gen yearstr_l=yearstr-0.4
rename estimate estimate_l
rename min95 min95_l
rename max95 max95_l
append using `tprod3'


twoway (scatter estimate yearstr , msize(medium) mcolor(dknavy))  (rspike   min95 max95 yearstr , lcolor(dknavy)) (scatter estimate_l yearstr_l ,msymbol(Oh)  msize(medium) mcolor(dkgreen))  (rspike   min95_l max95_l yearstr_l , lcolor(dkgreen)),  xsize(6) ysize(4) xtitle(Year, ) xline(1944, lcolor(maroon)) xline(1952, lcolor(maroon)) title("Panel A: DDD Estimates of ln Value of Production")  ///
 xlabel(1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970, ) plotregion(lcolor(white)) graphregion(lcolor(white) fcolor(white) color(white)) legend(order(1 "High-Skill exposure" 3 "Low-Skill exposure") position(6))  xlabel(#8)  xlabel(,grid nogextend ) ylabel(,grid nogextend)  ytitle("", margin(0 1 0 0))    saving(flexible_HS_prod_ddd.gph, replace)
 restore


*Production

preserve
clear all
set obs 1
gen year =1943
gen estimate = 0
gen parm ="repal1943"
gen min95 =0
gen max95 =0
gen parmseq =0
append using `t2'
keep if regexm(parm, "^repal*")
gen yearstr =substr(parm, -4,4)
destring yearstr, replace
sort yearstr
keep if parmseq<36
tempfile tlabor3
save `tlabor3'
*title(Panel B: ln Labor Force)
restore 

preserve
clear all
set obs 1
gen year =1943
gen estimate = 0
gen parm ="repao1943"
gen min95 =0
gen max95 =0
gen parmseq =0
append using `t2'
keep if regexm(parm, "^repao*")
gen yearstr =substr(parm, -4,4)
destring yearstr, replace
sort yearstr
keep if parmseq>35&parmseq<71
gen yearstr_l=yearstr-0.4
rename estimate estimate_l
rename min95 min95_l
rename max95 max95_l
append using `tlabor3'


twoway (scatter estimate yearstr , msize(medium) mcolor(dknavy))  (rspike   min95 max95 yearstr , lcolor(dknavy)) (scatter estimate_l yearstr_l , msymbol(Oh)  msize(medium) mcolor(dkgreen))  (rspike   min95_l max95_l yearstr_l , lcolor(dkgreen)),  xsize(6) ysize(4) xtitle(Year, ) xline(1944, lcolor(maroon)) xline(1952, lcolor(maroon)) title("Panel B: DDD Estimates of ln Labor Force")  ///
 xlabel(1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970, ) plotregion(lcolor(white)) graphregion(lcolor(white) fcolor(white) color(white)) legend(order(1 "High-Skill exposure" 3 "Low-Skill exposure") position(6))  xlabel(#8)  xlabel(,grid nogextend ) ylabel(,grid nogextend)  ytitle("", margin(0 1 0 0))    saving(flexible_HS_labor_ddd.gph, replace)
 restore

*Combine files

graph combine flexible_HS_prod.gph   flexible_HS_prod_ddd.gph flexible_HS_labor.gph flexible_HS_labor_ddd.gph , row(2) col(2) iscale(.6) ysize(5) xsize(10) commonscheme  graphregion(fcolor(white) color(white))

graph export "$graphs/combined_flexible_hs_ls.eps",as(eps)   font(Times) replace
graph export "$graphs/combined_flexible_group_hs_ls.pdf",as(pdf)   font(Times) replace
